package cn.itcast.stream;

import cn.itcast.entity.UserEntity;

import java.util.ArrayList;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class ListToSet {
    public static void main(String[] args) {

        ArrayList<UserEntity> userEntities = new ArrayList<>();
        userEntities.add(new UserEntity("张三",18));
        userEntities.add(new UserEntity("李四",26));
        userEntities.add(new UserEntity("王二",10));

        userEntities.add(new UserEntity("麻子",28));


        /**
         * 创建Stream的方式有两种
         *  1.串行流stream() 单线程
         *  2.并行流parallelStream
         */

        Stream<UserEntity> stream = userEntities.stream();
        //转换成set集合
        Set<UserEntity> setUserList = stream.collect(Collectors.toSet());
        setUserList.forEach(userEntity -> System.out.println(userEntity.toString()));




    }
}
